<?php 
// 中文编码
header('content-type:text/html;charset=utf-8;');
$link=mysqli_connect('127.0.0.1','root','root','mi');
$username=$_REQUEST['un'];
$password=$_REQUEST['pw'];

// echo $username,$password;
$sql = "SELECT * FROM `userinfo` WHERE `username`='$username'";
$arr=mysqli_query($link,$sql);
$res=mysqli_fetch_all($arr);
if($res){
    //表示存在
    $new_arr = array('code' => 1);
}else{
    $new_arr = array('code' => 0);
    $sql = "INSERT INTO `userinfo` (`username`,`password`) VALUES ('$username','$password')";
    $res = mysqli_query($link, $sql);
    //注册成功，记录cookie
    setcookie('username', $username);

}
echo $jsonstr=json_encode($new_arr);